from apps.common.base.dao import BaseDao
from apps.pay.order.serializers import *

class OrderDao(BaseDao):
    MODEL_CLASS = Order
    SERI_CLASS = OrderBaseSerializer

    def findOneByOrderId(self, orderId):
        orders = self.findAll().filter(orderId=orderId)
        if orders.exists():
            return orders.first()
        else:
            print('订单ID不存在', orderId)
            return None
        
    def findAllMainOrder(self):
        return self.findAll().filter(order__isnull=True)
    
    def findAllSubOrder(self):
        return self.findAll().exclude(order__isnull=True)